home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / game / shoot / ADescentSrc.lha / descent / main / paging.c < prev    next >
C/C++ Source or Header  |  1998-03-03  |  12KB  |  490 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: /usr/CVS/descent/main/paging.c,v $
  15.  * $Revision: 1.1.1.1 $
  16.  * $Author: nobody $
  17.  * $Date: 1998/03/03 15:12:28 $
  18.  * 
  19.  * Routines for paging in/out textures.
  20.  * 
  21.  * $Log: paging.c,v $
  22.  * Revision 1.1.1.1  1998/03/03 15:12:28  nobody
  23.  * reimport after crash from backup
  24.  *
  25.  * Revision 1.1.1.1  1998/02/13  20:20:56  hfrieden
  26.  * Initial Import
  27.  *
  28.  * Revision 2.5  1995/10/07  13:18:21  john
  29.  * Added PSX debugging stuff that builds .PAG files.
  30.  * 
  31.  * Revision 2.4  1995/08/24  13:40:03  john
  32.  * Added code to page in vclip for powerup disapperance and to 
  33.  * fix bug that made robot makers not page in the correct bot
  34.  * textures.
  35.  * 
  36.  * Revision 2.3  1995/07/26  12:09:19  john
  37.  * Made code that pages in weapon_info->robot_hit_vclip not
  38.  * page in unless it is a badass weapon.  Took out old functionallity
  39.  * of using this if no robot exp1_vclip, since all robots have these.
  40.  * 
  41.  * Revision 2.2  1995/07/24  13:22:11  john
  42.  * Made sure everything gets paged in at the
  43.  * level start.  Fixed bug with robot effects not
  44.  * getting paged in correctly.
  45.  * 
  46.  * Revision 2.1  1995/05/12  15:50:16  allender
  47.  * fix to check effects dest_bm_num > -1 before paging in
  48.  * 
  49.  * Revision 2.0  1995/02/27  11:27:39  john
  50.  * New version 2.0, which has no anonymous unions, builds with
  51.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  52.  * 
  53.  * Revision 1.18  1995/02/22  14:12:28  allender
  54.  * remove anonyous union from object structure
  55.  * 
  56.  * Revision 1.17  1995/02/11  22:54:15  john
  57.  * Made loading for pig not show up for demos.
  58.  * 
  59.  * Revision 1.16  1995/02/11  22:37:04  john
  60.  * Made cockpit redraw.
  61.  * 
  62.  * Revision 1.15  1995/01/28  16:29:35  john
  63.  * *** empty log message ***
  64.  * 
  65.  * Revision 1.14  1995/01/27  17:16:18  john
  66.  * Added code to page in all the weapons.
  67.  * 
  68.  * Revision 1.13  1995/01/24  21:51:22  matt
  69.  * Clear the boxed message to fix a mem leakage
  70.  * 
  71.  * Revision 1.12  1995/01/23  13:00:46  john
  72.  * Added hostage vclip paging.
  73.  * 
  74.  * Revision 1.11  1995/01/23  12:29:52  john
  75.  * Added code to page in eclip on robots, dead control center,
  76.  * gauges bitmaps, and weapon pictures.
  77.  * 
  78.  * Revision 1.10  1995/01/21  12:54:15  adam
  79.  * *** empty log message ***
  80.  * 
  81.  * Revision 1.9  1995/01/21  12:41:29  adam
  82.  * changed orb to loading box
  83.  * 
  84.  * Revision 1.8  1995/01/18  15:09:02  john
  85.  * Added start/stop time around paging.
  86.  * Made paging clear screen around globe.
  87.  * 
  88.  * Revision 1.7  1995/01/18  10:37:00  john
  89.  * Added code to page in exploding monitors.
  90.  * 
  91.  * Revision 1.6  1995/01/17  19:03:35  john
  92.  * Added cool spinning orb during loading.
  93.  * 
  94.  * Revision 1.5  1995/01/17  14:49:26  john
  95.  * Paged in weapons.
  96.  * 
  97.  * Revision 1.4  1995/01/17  12:14:07  john
  98.  * Made walls, object explosion vclips load at level start.
  99.  * 
  100.  * Revision 1.3  1995/01/15  13:23:24  john
  101.  * First working version
  102.  * 
  103.  * Revision 1.2  1995/01/15  11:56:45  john
  104.  * Working version of paging.
  105.  * 
  106.  * Revision 1.1  1995/01/15  11:33:37  john
  107.  * Initial revision
  108.  * 
  109.  * 
  110.  */
  111.  
  112.  
  113. #pragma off (unreferenced)
  114. static char rcsid[] = "$Id: paging.c,v 1.1.1.1 1998/03/03 15:12:28 nobody Exp $";
  115. #pragma on (unreferenced)
  116.  
  117.  
  118. #include <stdio.h>
  119. #include <stdlib.h>
  120. #include <math.h>
  121. #include <string.h>
  122.  
  123. #include "mono.h"
  124. #include "inferno.h"
  125. #include "segment.h"
  126. #include "textures.h"
  127. #include "wall.h"
  128. #include "object.h"
  129. #include "gamemine.h"
  130. #include "error.h"
  131. #include "gameseg.h"
  132. #include "game.h"
  133. #include "piggy.h"
  134. #include "texmerge.h"
  135. #include "polyobj.h"
  136. #include "vclip.h"
  137. #include "effects.h"
  138. #include "fireball.h"
  139. #include "weapon.h"
  140. #include "palette.h"
  141. #include "timer.h"
  142. #include "text.h"
  143. #include "cntrlcen.h"
  144. #include "gauges.h"
  145. #include "powerup.h"
  146. #include "fuelcen.h"
  147.  
  148. void paging_touch_vclip( vclip * vc )
  149. {
  150.     int i;
  151.  
  152.     for (i=0; i<vc->num_frames; i++ )   {
  153.         PIGGY_PAGE_IN( vc->frames[i] );
  154.     }
  155. }
  156.  
  157. void paging_touch_wall_effects( int tmap_num )
  158. {
  159.     int i;
  160.  
  161.     for (i=0;i<Num_effects;i++) {
  162.         if ( Effects[i].changing_wall_texture == tmap_num ) {
  163.             paging_touch_vclip( &Effects[i].vc );
  164.  
  165.             if (Effects[i].dest_bm_num > -1)
  166.                 PIGGY_PAGE_IN( Textures[Effects[i].dest_bm_num] );  //use this bitmap when monitor destroyed
  167.             if ( Effects[i].dest_vclip > -1 )
  168.                 paging_touch_vclip( &Vclip[Effects[i].dest_vclip] );          //what vclip to play when exploding
  169.  
  170.             if ( Effects[i].dest_eclip > -1 )
  171.                 paging_touch_vclip( &Effects[Effects[i].dest_eclip].vc ); //what eclip to play when exploding
  172.  
  173.             if ( Effects[i].crit_clip > -1 )
  174.                 paging_touch_vclip( &Effects[Effects[i].crit_clip].vc ); //what eclip to play when mine critical
  175.         }
  176.  
  177.     }
  178. }
  179.  
  180. void paging_touch_object_effects( int tmap_num )
  181. {
  182.     int i;
  183.  
  184.     for (i=0;i<Num_effects;i++) {
  185.         if ( Effects[i].changing_object_texture == tmap_num )   {
  186.             paging_touch_vclip( &Effects[i].vc );
  187.         }
  188.     }
  189. }
  190.  
  191.  
  192. void paging_touch_model( int modelnum )
  193. {
  194.     int i;
  195.     polymodel *pm = &Polygon_models[modelnum];
  196.  
  197.     for (i=0;i<pm->n_textures;i++)  {
  198.         PIGGY_PAGE_IN( ObjBitmaps[ObjBitmapPtrs[pm->first_texture+i]] );
  199.         paging_touch_object_effects( ObjBitmapPtrs[pm->first_texture+i] );
  200.         //paging_touch_object_effects( pm->first_texture+i );
  201.     }
  202. }
  203.  
  204. void paging_touch_weapon( int weapon_type )
  205. {
  206.     // Page in the robot's weapons.
  207.     
  208.     if ( (weapon_type < 0) || (weapon_type > N_weapon_types) ) return;
  209.  
  210.     if ( Weapon_info[weapon_type].picture.index )   {
  211.         PIGGY_PAGE_IN( Weapon_info[weapon_type].picture );
  212.     }       
  213.     
  214.     if ( Weapon_info[weapon_type].flash_vclip > -1 )
  215.         paging_touch_vclip(&Vclip[Weapon_info[weapon_type].flash_vclip]);
  216.     if ( Weapon_info[weapon_type].wall_hit_vclip > -1 )
  217.         paging_touch_vclip(&Vclip[Weapon_info[weapon_type].wall_hit_vclip]);
  218.     if ( Weapon_info[weapon_type].damage_radius )   {
  219.         // Robot_hit_vclips are actually badass_vclips
  220.         if ( Weapon_info[weapon_type].robot_hit_vclip > -1 )
  221.             paging_touch_vclip(&Vclip[Weapon_info[weapon_type].robot_hit_vclip]);
  222.     }
  223.  
  224.     switch( Weapon_info[weapon_type].render_type )  {
  225.     case WEAPON_RENDER_VCLIP:
  226.         if ( Weapon_info[weapon_type].weapon_vclip > -1 )
  227.             paging_touch_vclip( &Vclip[Weapon_info[weapon_type].weapon_vclip] );
  228.         break;
  229.     case WEAPON_RENDER_NONE:
  230.         break;
  231.     case WEAPON_RENDER_POLYMODEL:
  232.         paging_touch_model( Weapon_info[weapon_type].model_num );
  233.         break;
  234.     case WEAPON_RENDER_BLOB:
  235.         PIGGY_PAGE_IN( Weapon_info[weapon_type].bitmap );
  236.         break;
  237.     }
  238. }
  239.  
  240.  
  241.  
  242. byte super_boss_gate_type_list[13] = {0, 1, 8, 9, 10, 11, 12, 15, 16, 18, 19, 20, 22 };
  243.  
  244. void paging_touch_robot( int robot_index )
  245. {
  246.     int i;
  247.     // Page in robot_index
  248.     paging_touch_model(Robot_info[robot_index].model_num);
  249.     if ( Robot_info[robot_index].exp1_vclip_num>-1 )
  250.         paging_touch_vclip(&Vclip[Robot_info[robot_index].exp1_vclip_num]);
  251.     if ( Robot_info[robot_index].exp2_vclip_num>-1 )
  252.         paging_touch_vclip(&Vclip[Robot_info[robot_index].exp2_vclip_num]);
  253.  
  254.     // Page in his weapons
  255.     paging_touch_weapon( Robot_info[robot_index].weapon_type );
  256.  
  257.     // A super-boss can gate in robots...
  258.     if ( Robot_info[robot_index].boss_flag==2 ) {
  259.         for (i=0; i<13; i++ )
  260.             paging_touch_robot(super_boss_gate_type_list[i]);
  261.  
  262.         paging_touch_vclip( &Vclip[VCLIP_MORPHING_ROBOT] );
  263.     }
  264. }
  265.  
  266.  
  267. void paging_touch_object( object * obj )
  268. {
  269.     int v;
  270.  
  271.     switch (obj->render_type) {
  272.  
  273.         case RT_NONE:   break;      //doesn't render, like the player
  274.  
  275.         case RT_POLYOBJ:
  276.             paging_touch_model(obj->rtype.pobj_info.model_num);
  277.             break;
  278.  
  279.         case RT_POWERUP: 
  280.             if ( obj->rtype.vclip_info.vclip_num > -1 )
  281.                 paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
  282.             break;
  283.  
  284.         case RT_MORPH:  break;
  285.  
  286.         case RT_FIREBALL: break;
  287.  
  288.         case RT_WEAPON_VCLIP: break;
  289.  
  290.         case RT_HOSTAGE: 
  291.             paging_touch_vclip(&Vclip[obj->rtype.vclip_info.vclip_num]);
  292.             break;
  293.  
  294.         case RT_LASER: break;
  295.     }
  296.  
  297.     switch (obj->type) {    
  298.     case OBJ_PLAYER:    
  299.         v = get_explosion_vclip(obj, 0);
  300.         if ( v > -1 )
  301.             paging_touch_vclip(&Vclip[v]);
  302.         break;
  303.     case OBJ_ROBOT:
  304.         paging_touch_robot( obj->id );
  305.         break;
  306.     case OBJ_CNTRLCEN:
  307.         paging_touch_weapon( CONTROLCEN_WEAPON_NUM );
  308.         if (Dead_modelnums[obj->rtype.pobj_info.model_num] != -1)   {
  309.             paging_touch_model( Dead_modelnums[obj->rtype.pobj_info.model_num] );
  310.         }
  311.         break;
  312.     }
  313. }
  314.  
  315.     
  316.  
  317. void paging_touch_side( segment * segp, int sidenum )
  318. {
  319.     int tmap1, tmap2;
  320.  
  321.     if (!(WALL_IS_DOORWAY(segp,sidenum) & WID_RENDER_FLAG))
  322.         return;
  323.     
  324.     tmap1 = segp->sides[sidenum].tmap_num;
  325.  
  326.     paging_touch_wall_effects(tmap1);
  327.     tmap2 = segp->sides[sidenum].tmap_num2;
  328.     if (tmap2 != 0) {
  329.         texmerge_get_cached_bitmap( tmap1, tmap2 );
  330.         paging_touch_wall_effects( tmap2 & 0x3FFF );
  331.     } else  {
  332.         PIGGY_PAGE_IN( Textures[tmap1] );
  333.     }
  334.  
  335. }
  336.  
  337. void paging_touch_robot_maker( segment * segp )
  338. {
  339.     if ( segp->special == SEGMENT_IS_ROBOTMAKER )   {
  340.         paging_touch_vclip(&Vclip[VCLIP_MORPHING_ROBOT]);
  341.         if (RobotCenters[segp->matcen_num].robot_flags != 0) {
  342.             uint    flags;
  343.             int robot_index;
  344.  
  345.             robot_index = 0;
  346.             flags = RobotCenters[segp->matcen_num].robot_flags;
  347.             while (flags) {
  348.                 if (flags & 1)  {
  349.                     // Page in robot_index
  350.                     paging_touch_robot( robot_index );
  351.                 }
  352.                 flags >>= 1;
  353.                 robot_index++;
  354.             }
  355.         }
  356.     }
  357. }
  358.  
  359.  
  360. void paging_touch_segment(segment * segp)
  361. {
  362.     int sn;
  363.     int objnum;
  364.  
  365.     if ( segp->special == SEGMENT_IS_ROBOTMAKER )   
  366.         paging_touch_robot_maker(segp);
  367.  
  368.     for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) {
  369.         paging_touch_side( segp, sn );
  370.     }
  371.  
  372.     for (objnum=segp->objects;objnum!=-1;objnum=Objects[objnum].next)   {
  373.         paging_touch_object( &Objects[objnum] );
  374.     }
  375. }
  376.  
  377.  
  378.  
  379. void paging_touch_walls()
  380. {
  381.     int i,j;
  382.     wclip *anim;
  383.  
  384.     for (i=0;i<Num_walls;i++) {
  385. //      paging_draw_orb();
  386.         if ( Walls[i].clip_num > -1 )   {
  387.             anim = &WallAnims[Walls[i].clip_num];
  388.             for (j=0; j < anim->num_frames; j++ )   {
  389.                 PIGGY_PAGE_IN( Textures[anim->frames[j]] );
  390.             }
  391.         }
  392.     }
  393. }
  394.  
  395.  
  396. void paging_touch_all()
  397. {
  398.     int black_screen;
  399.     int s;
  400.     
  401.     stop_time();
  402.  
  403.     black_screen = gr_palette_faded_out;
  404.  
  405.     if ( gr_palette_faded_out ) {
  406.         gr_clear_canvas( 0 );
  407.         gr_palette_load( gr_palette );
  408.     }
  409.     
  410.     show_boxed_message(TXT_LOADING);
  411.  
  412.     mprintf(( 0, "Loading all textures in mine..." ));
  413.  
  414.  
  415.     for (s=0; s<=Highest_segment_index; s++)    {
  416.         paging_touch_segment( &Segments[s] );
  417.     }   
  418.     paging_touch_walls();
  419.  
  420.     for ( s=0; s < N_powerup_types; s++ )   {
  421.         if ( Powerup_info[s].vclip_num > -1 )   
  422.             paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
  423.     }
  424.  
  425.     for ( s=0; s<N_weapon_types; s++ )  {
  426.         paging_touch_weapon(s);
  427.     }
  428.  
  429.     for ( s=0; s < N_powerup_types; s++ )   {
  430.         if ( Powerup_info[s].vclip_num > -1 )   
  431.             paging_touch_vclip(&Vclip[Powerup_info[s].vclip_num]);
  432.     }
  433.  
  434.  
  435.     for (s=0; s<MAX_GAUGE_BMS; s++ )    {
  436.         if ( Gauges[s].index )  {
  437.             PIGGY_PAGE_IN( Gauges[s] );
  438.         }
  439.     }
  440.  
  441.     paging_touch_vclip( &Vclip[VCLIP_PLAYER_APPEARANCE] );
  442.  
  443.     paging_touch_vclip( &Vclip[VCLIP_POWERUP_DISAPPEARANCE] );
  444.  
  445.     mprintf(( 0, "done\n" ));
  446.  
  447.     clear_boxed_message();
  448.  
  449.     if ( black_screen ) {
  450.         gr_palette_clear();
  451.         gr_clear_canvas( 0 );
  452.     }
  453.     start_time();
  454.     reset_cockpit();        //force cockpit redraw next time
  455.  
  456. #ifdef PSX_BUILD_TOOLS
  457.     {
  458.         extern int Current_level_num;
  459.         extern ushort GameBitmapXlat[MAX_BITMAP_FILES];
  460.         FILE * fp;
  461.         char fname[128];
  462.         int i;
  463.  
  464.         if ( Current_level_num < 0 )
  465.             sprintf( fname, "levels%d.pag", -Current_level_num );
  466.         else    
  467.             sprintf( fname, "level%02d.pag", Current_level_num );
  468.         fp = fopen( fname, "wt" );
  469.         for (i=0; i<MAX_BITMAP_FILES;i++ )  {
  470.             int paged_in = 1;
  471.             piggy_get_bitmap_name(i,fname);
  472.  
  473.             if (GameBitmaps[i].bm_flags & BM_FLAG_PAGED_OUT) 
  474.                 paged_in = 0;
  475.             if (GameBitmapXlat[i]!=i)
  476.                 paged_in = 0;
  477.             if ( (i==47) || (i==48) )       // Mark red mplayer ship textures as paged in.
  478.                 paged_in = 1;
  479.     
  480.             if ( !paged_in )
  481.                 fprintf( fp, "0,\t// Bitmap %d (%s)\n", i, fname );
  482.             else
  483.                 fprintf( fp, "1,\t// Bitmap %d (%s)\n", i, fname );
  484.         }
  485.         fclose(fp);
  486.     }
  487. #endif
  488.  
  489. }
  490.